﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SoliderStateDef
{
    public const string StandBy = "standby";
    public const string MovePoint = "movePoint";
    public const string Search = "search";
    public const string Attack = "attack";

    public static SoliderStateStandby s_stateStandby = new SoliderStateStandby();
    public static SoliderStateMovePoint s_stateMovePoint = new SoliderStateMovePoint();
    public static SoliderStateSearch s_stateSearch = new SoliderStateSearch();
    public static SoliderStateAttack s_stateAttack = new SoliderStateAttack();
}

/// <summary>
/// 士兵 待机状态
/// </summary>
public class SoliderStateStandby : NState<EntitySolider>
{
    public void Enter(EntitySolider entity, params object[] args)
    {
        entity.Veh.CloseAllSteer();
        entity.PlayClip(BattleDef.s_strClipName_Idle, true);
    }

    public void Execute(EntitySolider entity, params object[] args)
    {
    }

    public void Exit(EntitySolider entity, params object[] args)
    {
    }

    public bool OnMessage(EntitySolider entity, MessageBody message)
    {
        return false;
    }
}

/// <summary>
/// 士兵 移动到某点的状态
/// </summary>
public class SoliderStateMovePoint : NState<EntitySolider>
{
    public void Enter(EntitySolider entity, params object[] args)
    {
        Vector3 tag = (Vector3)args[0];
        Action cb = (Action)args[1];

        entity.PlayClip(BattleDef.s_strClipName_Run, true);
        entity.Veh.SetSteerForPoint(tag, (steer)=> 
        {
            if (cb != null)
                cb();
        });
        entity.Veh.SetSteerState(SteerName.StN_SteerSeparation, false);
    }

    public void Execute(EntitySolider entity, params object[] args)
    {
        
    }

    public void Exit(EntitySolider entity, params object[] args)
    {
        
    }

    public bool OnMessage(EntitySolider entity, MessageBody message)
    {
        return false;
    }
}

/// <summary>
/// 士兵 向某个方向移动 移动过程中检测攻击对象
/// </summary>
public class SoliderStateSearch : NState<EntitySolider>
{
    public void Enter(EntitySolider entity, params object[] args)
    {
        entity.PlayClip(BattleDef.s_strClipName_Run, true);
        entity.Veh.CloseAllSteer();
        entity.Veh.SetSteerState(SteerName.StN_SteerForward,true);
    }

    public void Execute(EntitySolider entity, params object[] args)
    {
    }

    public void Exit(EntitySolider entity, params object[] args)
    {
    }

    public bool OnMessage(EntitySolider entity, MessageBody message)
    {
        return false;
    }
}

/// <summary>
/// 攻击状态一直在播放攻击动画
/// </summary>
public class SoliderStateAttack : NState<EntitySolider>
{
    public void Enter(EntitySolider entity, params object[] args)
    {
        entity.Veh.CloseAllSteer();
        entity.PlayClip(BattleDef.s_strClipName_Attack, true);
    }

    public void Execute(EntitySolider entity, params object[] args)
    {
    }

    public void Exit(EntitySolider entity, params object[] args)
    {
    }

    public bool OnMessage(EntitySolider entity, MessageBody message)
    {
        return false;
    }
}
